package top.wshape1.shiziapi.mock.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-10-08
 */

@Configuration
public class JsEngineConfig {

    @Bean
    public ScriptEngine scriptEngine() throws IOException, ScriptException {
        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine engine = scriptEngineManager.getEngineByName("graal.js");
        engine.eval(new InputStreamReader(new ClassPathResource("js/mock-min.js").getInputStream()));
        return engine;
    }

}
